package net.yla.smartbus.module.ba.SendSMS.service.impl;

import net.yla.smartbus.module.ba.SendSMS.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Author :
 * @Create_Date : 2019/11/28/16:15
 * @Pack_name : net.seocoo.smartbus.module.ps.sendSms.service.impl : RedisServiceImpl
 * ****************************************
 * 注释:
 */
@Service
public class RedisutilImpl implements RedisService {


    @Autowired
    private StringRedisTemplate template;

    /**
     * 存值
     * @param key  键
     * @param value 值
     */
    @Override
    public void set(String key, String value) {
        ValueOperations<String, String> operations = template.opsForValue();

        operations.set(key,value);
    }

    /**
     * 存值设置保存时间
     * @param key 键
     * @param value 值
     * @param timeout 超时(秒)
     */
    @Override
    public void set(String key, String value, int timeout) {
        ValueOperations<String, String> operations = template.opsForValue();
        operations.set(key,value, timeout, TimeUnit.SECONDS);
    }

    @Override
    public String get(String key) {
        ValueOperations<String, String> operations = template.opsForValue();
        return operations.get(key);
    }

    @Override
    public void del(String key) {
        template.delete(key);
    }
}
